﻿using BCCServer.Common.Common;
using BCCServer.DAO.Interfaces;
using BCCServer.DAO.login;
using BCCServer.IService.ILoginService;
using BCCServer.Model.Models;
using BCCServer.Model.ModelsOut;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BCCServer.Service.LoginService
{
    public class Login:ILogin
    {
        private readonly IloginDB logindb;

        public Login(IloginDB logindb)
        {
            this.logindb = logindb;
        }

        /// <summary>
        /// 根据账号查询信息并登录
        /// </summary>
        /// <param name="sendAccount"></param>
        /// <param name="receiveAccount"></param>
        /// <returns></returns>
        public  BCCUserOut selLogin(string Account, string pwd)
        {
            try
            {
                var rs = logindb.selLogin(Account, pwd);
                if (rs != null&& !string.IsNullOrEmpty(rs.Account))
                {
                    rs.token = TokenHelper.GenToken(new TokenInfo { UserName = rs.Account });
                }
                return rs;
            }
            catch (Exception)
            {
                return null;
            }
            
            
        }
    }
}
